package com.warm.pump.module.sys.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.sys.bean.po.gen.SysConfig;
import com.warm.pump.module.sys.mapper.gen.SysConfigMapper;
import com.warm.pump.module.sys.bean.po.gen.SysConfigExample;

@Repository
public class SysConfigDao {
    // 日志对象
    private transient Log log = LogFactory.getLog(this.getClass());
    @Autowired
    private SysConfigMapper sysConfigMapper;

    // 增加一个后台SysConfig表

    public boolean insert(SysConfig sysConfig) {
        try {
            sysConfigMapper.insert(sysConfig);
            log.debug("后台SysConfig表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig表增加失败");
            throw new ServiceException("后台SysConfig表增加失败", e);
        }
    }
    // 增加一个后台SysConfig表Selective

    public boolean insertSelective(SysConfig sysConfig) {
        try {
            sysConfigMapper.insertSelective(sysConfig);
            log.debug("后台SysConfig表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig表增加失败");
            throw new ServiceException("后台SysConfig表增加失败", e);
        }
    }

    // 删除一个后台SysConfig表

    public boolean deleteByPrimaryKey(Long id) {
        try {
            sysConfigMapper.deleteByPrimaryKey(id);
            log.debug("后台SysConfig表删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig表删除失败");
            throw new ServiceException("后台SysConfig表删除失败", e);
        }
    }
    // 删除一个后台SysConfig表byMap

    public boolean deleteByMap(Map sysConfigMap) {
        try {
            sysConfigMapper.deleteByExample(createSysConfigExample(sysConfigMap, null, null));
            log.debug("后台SysConfig根据Map删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig根据GroupID删除失败");
            throw new ServiceException("后台SysConfig根据object删除失败", e);
        }
    }
    // 修改一个后台SysConfig表

    public boolean updateByPrimaryKey(SysConfig sysConfig) {
        try {
            sysConfigMapper.updateByPrimaryKey(sysConfig);
            log.debug("后台SysConfig表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig表修改失败");
            throw new ServiceException("后台SysConfig表修改失败", e);
        }
    }
    // 修改一个后台SysConfig表Selective

    public boolean updateByPrimaryKeySelective(SysConfig sysConfig) {
        try {
            sysConfigMapper.updateByPrimaryKeySelective(sysConfig);
            log.debug("后台SysConfig表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysConfig表修改失败");
            throw new ServiceException("后台SysConfig表修改失败", e);
        }
    }
    // 修改一个后台SysConfig表

    public boolean updateByMap(SysConfig sysConfig, Map sysConfigMap) {
        try {
            sysConfigMapper.updateByExample(sysConfig, createSysConfigExample(sysConfigMap, null, null));
            log.debug("后台批量SysConfig表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量SysConfig表修改失败");
            throw new ServiceException("后台SysConfig表批量修改失败", e);
        }
    }
    // 修改一个后台SysConfig表Selective

    public boolean updateByMapSelective(SysConfig sysConfig, Map sysConfigMap) {
        try {
            sysConfigMapper.updateByExampleSelective(sysConfig, createSysConfigExample(sysConfigMap, null, null));
            log.debug("后台批量SysConfig表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量SysConfig表修改失败");
            throw new ServiceException("后台SysConfig表批量修改失败", e);
        }
    }

    // 查询一个后台SysConfig表

    public SysConfig selectByPrimaryKey(Long id) {
        return sysConfigMapper.selectByPrimaryKey(id);
    }

    // 查询一个后台SysConfig表-根据map

    public SysConfig selectByMap(Map sysConfigMap) {
        List<SysConfig> list = getListByMap(sysConfigMap);
        if (list == null || list.isEmpty()) {
            return null;
        } else {
            return list.get(0);
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 查询所有后台SysConfig表

    public List<SysConfig> getListByMap(Map sysConfigMap) {

        return sysConfigMapper.selectByExample(createSysConfigExample(sysConfigMap, null, null));
    }

    //统计后台SysConfig表数量

    public int countTotalByMap(Map sysConfigMap) {

        return sysConfigMapper.countByExample(createSysConfigExample(sysConfigMap, null, null));
    }


    public List<SysConfig> getListByMapPage(Map sysConfigMap, int limitStart,
                                            int limitOffset) {

        return sysConfigMapper.selectByExample(createSysConfigExample(sysConfigMap, limitStart, limitOffset));
    }


    public PageBean getPageBeanByMap(Map sysConfigMap, int pageNo, int pageSize) {
        Integer count = countTotalByMap(sysConfigMap);
        PageBean pageBean = new PageBean();
        pageBean.setCount(count);
        pageBean.setPageNo(pageNo);
        pageBean.setPageSize(pageSize);
        int limitStart = pageBean.getStartNo();
        int limitOffset = pageSize;
        pageBean.setData(sysConfigMapper.selectByExample(createSysConfigExample(sysConfigMap, limitStart, limitOffset)));
        return pageBean;
    }

    private SysConfigExample createSysConfigExample(Map sysConfigMap, Integer limitStart, Integer limitOffset) {
        SysConfigExample sysConfigEx = new SysConfigExample();
        SysConfigExample.Criteria c = sysConfigEx.createCriteria();
        Long id_null = TypeCast.getLong(sysConfigMap.get("id_null"));
        Long id_notNull = TypeCast.getLong(sysConfigMap.get("id_notNull"));
        Long id = TypeCast.getLong(sysConfigMap.get("id"));
        Long id_not = TypeCast.getLong(sysConfigMap.get("id_not"));
        Long id_greater = TypeCast.getLong(sysConfigMap.get("id_greater"));
        Long id_greaterEqual = TypeCast.getLong(sysConfigMap.get("id_greaterEqual"));
        Long id_less = TypeCast.getLong(sysConfigMap.get("id_less"));
        Long id_lessEqual = TypeCast.getLong(sysConfigMap.get("id_lessEqual"));
        List<Long> id_in = TypeCast.getLongList(sysConfigMap.get("id_in"));
        List<Long> id_notIn = TypeCast.getLongList(sysConfigMap.get("id_notIn"));
        Long id_between1 = TypeCast.getLong(sysConfigMap.get("id_between1"));
        Long id_between2 = TypeCast.getLong(sysConfigMap.get("id_between2"));
        Long id_notBetween1 = TypeCast.getLong(sysConfigMap.get("id_notBetween1"));
        Long id_notBetween2 = TypeCast.getLong(sysConfigMap.get("id_notBetween2"));

        if (id_null != null) {
            c.andIdIsNull();
        }
        if (id_notNull != null) {
            c.andIdIsNotNull();
        }
        if (id != null) {
            c.andIdEqualTo(id);
        }
        if (id_not != null) {
            c.andIdNotEqualTo(id_not);
        }
        if (id_greater != null) {
            c.andIdGreaterThan(id_greater);
        }
        if (id_greaterEqual != null) {
            c.andIdGreaterThanOrEqualTo(id_greaterEqual);
        }
        if (id_less != null) {
            c.andIdLessThan(id_less);
        }
        if (id_lessEqual != null) {
            c.andIdLessThanOrEqualTo(id_lessEqual);
        }
        if (id_in != null) {
            c.andIdIn(id_in);
        }
        if (id_notIn != null) {
            c.andIdNotIn(id_notIn);
        }
        if (id_between1 != null) {
            c.andIdBetween(id_between1, id_between2);
        }
        if (id_notBetween1 != null) {
            c.andIdNotBetween(id_notBetween1, id_notBetween2);
        }
        String key_null = TypeCast.getString(sysConfigMap.get("key_null"));
        String key_notNull = TypeCast.getString(sysConfigMap.get("key_notNull"));
        String key = TypeCast.getString(sysConfigMap.get("key"));
        String key_not = TypeCast.getString(sysConfigMap.get("key_not"));
        String key_greater = TypeCast.getString(sysConfigMap.get("key_greater"));
        String key_greaterEqual = TypeCast.getString(sysConfigMap.get("key_greaterEqual"));
        String key_less = TypeCast.getString(sysConfigMap.get("key_less"));
        String key_lessEqual = TypeCast.getString(sysConfigMap.get("key_lessEqual"));
        String key_like = TypeCast.getString(sysConfigMap.get("key_like"));
        String key_notLike = TypeCast.getString(sysConfigMap.get("key_notLike"));
        List<String> key_in = TypeCast.getStringList(sysConfigMap.get("key_in"));
        List<String> key_notIn = TypeCast.getStringList(sysConfigMap.get("key_notIn"));
        String key_between1 = TypeCast.getString(sysConfigMap.get("key_between1"));
        String key_between2 = TypeCast.getString(sysConfigMap.get("key_between2"));
        String key_notBetween1 = TypeCast.getString(sysConfigMap.get("key_notBetween1"));
        String key_notBetween2 = TypeCast.getString(sysConfigMap.get("key_notBetween2"));

        if (key_null != null) {
            c.andKeyIsNull();
        }
        if (key_notNull != null) {
            c.andKeyIsNotNull();
        }
        if (key != null) {
            c.andKeyEqualTo(key);
        }
        if (key_not != null) {
            c.andKeyNotEqualTo(key_not);
        }
        if (key_greater != null) {
            c.andKeyGreaterThan(key_greater);
        }
        if (key_greaterEqual != null) {
            c.andKeyGreaterThanOrEqualTo(key_greaterEqual);
        }
        if (key_less != null) {
            c.andKeyLessThan(key_less);
        }
        if (key_lessEqual != null) {
            c.andKeyLessThanOrEqualTo(key_lessEqual);
        }
        if (key_like != null) {
            c.andKeyLike(key_like);
        }
        if (key_notLike != null) {
            c.andKeyNotLike(key_notLike);
        }
        if (key_in != null) {
            c.andKeyIn(key_in);
        }
        if (key_notIn != null) {
            c.andKeyNotIn(key_notIn);
        }
        if (key_between1 != null) {
            c.andKeyBetween(key_between1, key_between2);
        }
        if (key_notBetween1 != null) {
            c.andKeyNotBetween(key_notBetween1, key_notBetween2);
        }
        String value_null = TypeCast.getString(sysConfigMap.get("value_null"));
        String value_notNull = TypeCast.getString(sysConfigMap.get("value_notNull"));
        String value = TypeCast.getString(sysConfigMap.get("value"));
        String value_not = TypeCast.getString(sysConfigMap.get("value_not"));
        String value_greater = TypeCast.getString(sysConfigMap.get("value_greater"));
        String value_greaterEqual = TypeCast.getString(sysConfigMap.get("value_greaterEqual"));
        String value_less = TypeCast.getString(sysConfigMap.get("value_less"));
        String value_lessEqual = TypeCast.getString(sysConfigMap.get("value_lessEqual"));
        String value_like = TypeCast.getString(sysConfigMap.get("value_like"));
        String value_notLike = TypeCast.getString(sysConfigMap.get("value_notLike"));
        List<String> value_in = TypeCast.getStringList(sysConfigMap.get("value_in"));
        List<String> value_notIn = TypeCast.getStringList(sysConfigMap.get("value_notIn"));
        String value_between1 = TypeCast.getString(sysConfigMap.get("value_between1"));
        String value_between2 = TypeCast.getString(sysConfigMap.get("value_between2"));
        String value_notBetween1 = TypeCast.getString(sysConfigMap.get("value_notBetween1"));
        String value_notBetween2 = TypeCast.getString(sysConfigMap.get("value_notBetween2"));

        if (value_null != null) {
            c.andValueIsNull();
        }
        if (value_notNull != null) {
            c.andValueIsNotNull();
        }
        if (value != null) {
            c.andValueEqualTo(value);
        }
        if (value_not != null) {
            c.andValueNotEqualTo(value_not);
        }
        if (value_greater != null) {
            c.andValueGreaterThan(value_greater);
        }
        if (value_greaterEqual != null) {
            c.andValueGreaterThanOrEqualTo(value_greaterEqual);
        }
        if (value_less != null) {
            c.andValueLessThan(value_less);
        }
        if (value_lessEqual != null) {
            c.andValueLessThanOrEqualTo(value_lessEqual);
        }
        if (value_like != null) {
            c.andValueLike(value_like);
        }
        if (value_notLike != null) {
            c.andValueNotLike(value_notLike);
        }
        if (value_in != null) {
            c.andValueIn(value_in);
        }
        if (value_notIn != null) {
            c.andValueNotIn(value_notIn);
        }
        if (value_between1 != null) {
            c.andValueBetween(value_between1, value_between2);
        }
        if (value_notBetween1 != null) {
            c.andValueNotBetween(value_notBetween1, value_notBetween2);
        }
        String remark_null = TypeCast.getString(sysConfigMap.get("remark_null"));
        String remark_notNull = TypeCast.getString(sysConfigMap.get("remark_notNull"));
        String remark = TypeCast.getString(sysConfigMap.get("remark"));
        String remark_not = TypeCast.getString(sysConfigMap.get("remark_not"));
        String remark_greater = TypeCast.getString(sysConfigMap.get("remark_greater"));
        String remark_greaterEqual = TypeCast.getString(sysConfigMap.get("remark_greaterEqual"));
        String remark_less = TypeCast.getString(sysConfigMap.get("remark_less"));
        String remark_lessEqual = TypeCast.getString(sysConfigMap.get("remark_lessEqual"));
        String remark_like = TypeCast.getString(sysConfigMap.get("remark_like"));
        String remark_notLike = TypeCast.getString(sysConfigMap.get("remark_notLike"));
        List<String> remark_in = TypeCast.getStringList(sysConfigMap.get("remark_in"));
        List<String> remark_notIn = TypeCast.getStringList(sysConfigMap.get("remark_notIn"));
        String remark_between1 = TypeCast.getString(sysConfigMap.get("remark_between1"));
        String remark_between2 = TypeCast.getString(sysConfigMap.get("remark_between2"));
        String remark_notBetween1 = TypeCast.getString(sysConfigMap.get("remark_notBetween1"));
        String remark_notBetween2 = TypeCast.getString(sysConfigMap.get("remark_notBetween2"));

        if (remark_null != null) {
            c.andRemarkIsNull();
        }
        if (remark_notNull != null) {
            c.andRemarkIsNotNull();
        }
        if (remark != null) {
            c.andRemarkEqualTo(remark);
        }
        if (remark_not != null) {
            c.andRemarkNotEqualTo(remark_not);
        }
        if (remark_greater != null) {
            c.andRemarkGreaterThan(remark_greater);
        }
        if (remark_greaterEqual != null) {
            c.andRemarkGreaterThanOrEqualTo(remark_greaterEqual);
        }
        if (remark_less != null) {
            c.andRemarkLessThan(remark_less);
        }
        if (remark_lessEqual != null) {
            c.andRemarkLessThanOrEqualTo(remark_lessEqual);
        }
        if (remark_like != null) {
            c.andRemarkLike(remark_like);
        }
        if (remark_notLike != null) {
            c.andRemarkNotLike(remark_notLike);
        }
        if (remark_in != null) {
            c.andRemarkIn(remark_in);
        }
        if (remark_notIn != null) {
            c.andRemarkNotIn(remark_notIn);
        }
        if (remark_between1 != null) {
            c.andRemarkBetween(remark_between1, remark_between2);
        }
        if (remark_notBetween1 != null) {
            c.andRemarkNotBetween(remark_notBetween1, remark_notBetween2);
        }
        Integer status_null = TypeCast.getInteger(sysConfigMap.get("status_null"));
        Integer status_notNull = TypeCast.getInteger(sysConfigMap.get("status_notNull"));
        Integer status = TypeCast.getInteger(sysConfigMap.get("status"));
        Integer status_not = TypeCast.getInteger(sysConfigMap.get("status_not"));
        Integer status_greater = TypeCast.getInteger(sysConfigMap.get("status_greater"));
        Integer status_greaterEqual = TypeCast.getInteger(sysConfigMap.get("status_greaterEqual"));
        Integer status_less = TypeCast.getInteger(sysConfigMap.get("status_less"));
        Integer status_lessEqual = TypeCast.getInteger(sysConfigMap.get("status_lessEqual"));
        List<Integer> status_in = TypeCast.getIntegerList(sysConfigMap.get("status_in"));
        List<Integer> status_notIn = TypeCast.getIntegerList(sysConfigMap.get("status_notIn"));
        Integer status_between1 = TypeCast.getInteger(sysConfigMap.get("status_between1"));
        Integer status_between2 = TypeCast.getInteger(sysConfigMap.get("status_between2"));
        Integer status_notBetween1 = TypeCast.getInteger(sysConfigMap.get("status_notBetween1"));
        Integer status_notBetween2 = TypeCast.getInteger(sysConfigMap.get("status_notBetween2"));

        if (status_null != null) {
            c.andStatusIsNull();
        }
        if (status_notNull != null) {
            c.andStatusIsNotNull();
        }
        if (status != null) {
            c.andStatusEqualTo(status);
        }
        if (status_not != null) {
            c.andStatusNotEqualTo(status_not);
        }
        if (status_greater != null) {
            c.andStatusGreaterThan(status_greater);
        }
        if (status_greaterEqual != null) {
            c.andStatusGreaterThanOrEqualTo(status_greaterEqual);
        }
        if (status_less != null) {
            c.andStatusLessThan(status_less);
        }
        if (status_lessEqual != null) {
            c.andStatusLessThanOrEqualTo(status_lessEqual);
        }
        if (status_in != null) {
            c.andStatusIn(status_in);
        }
        if (status_notIn != null) {
            c.andStatusNotIn(status_notIn);
        }
        if (status_between1 != null) {
            c.andStatusBetween(status_between1, status_between2);
        }
        if (status_notBetween1 != null) {
            c.andStatusNotBetween(status_notBetween1, status_notBetween2);
        }
        if (sysConfigMap.get("orderBy") != null) {
            sysConfigEx.setOrderByClause((String) sysConfigMap.get("orderBy"));
        }
        if (limitStart != null && limitOffset != null) {
            sysConfigEx.setLimitStart(limitStart);
            sysConfigEx.setLimitOffset(limitOffset);
        }

        return sysConfigEx;
    }
}
